package com.zlf.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.zlf.util.ExceptionUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DemoController {

//    @SentinelResource(value = "/foo", blockHandler = "blockHandlerFooUtil", blockHandlerClass = ExceptionUtil.class)
//    @GetMapping("/foo")
//    public String test() {
//        return "Sentinel集成SpringCloud编码方式实现~~~~~~~~~~~success~~~~~~~~~~~";
//    }

    @GetMapping("/foo")
    @SentinelResource(value = "/foo", blockHandler = "blockHandlerFoo")
    public String foo() {
        return "Sentinel集成SpringCloud编码方式实现~~~~~~~~~~~success~~~~~~~~~~~";
    }

    public String blockHandlerFoo(BlockException e) {
        return "Sentinel集成SpringCloud编码方式实现~~~~~~~~~~~block~~~~~~~~~~~";
    }

    @GetMapping("/foo1")
    @SentinelResource(value = "/foo1", fallback = "fallbackFoo1")
    public String foo1() throws Exception {
        throw new Exception();
    }

    public String fallbackFoo1() {
        return "Sentinel集成SpringCloud编码方式实现~~~~~~~~~~~fallback~~~~~~~~~~~";
    }

}
